package javaBean;

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;

public class GetClassConstruceorsInfo {
    public static void main(String[] args) {
        Constructor[] cons = Person.class.getConstructors();
        System.out.println("-------------构造方法展示-------------");
        for (Constructor c : cons) {
            System.out.println("访问修饰符：");
            int modifiers = c.getModifiers();
            if((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC)
                System.out.println("public");
            else if((modifiers & Modifier.PROTECTED) == Modifier.PROTECTED)
                System.out.println("protected");
            else if((modifiers & Modifier.PRIVATE) == Modifier.PRIVATE)
                System.out.println("private");
            else
                System.out.println("default package");

            Class[] params=c.getParameterTypes();
            if(params.length == 0){
                System.out.println("该构造方法没有参数");
            }else {
                System.out.println("该构造方法的参数列表：");
                for(int i=0; i<params.length; i++){
                    if(i!=0)
                        System.out.print(", ");
                    System.out.print(params[i].getName());
                }

            }
            System.out.println("-------------------");
        }
    }
}
